package com.spider.controller;

import com.spider.service.DataService;
import com.spider.vo.BarVo;
import com.spider.vo.DataVo;
import com.spider.vo.ResultVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 对应数据展示页面
 * @author panglin
 * @date 2020/11/22 9:53
 */
@RestController
@RequestMapping("api/data")
public class DataController {

    @Resource
    private DataService dataService;

    @GetMapping("all")
    public ResultVo getAll(@RequestParam("condition")String condition,@RequestParam("pageSize")Integer size,@RequestParam("pageNum")Integer num){
        DataVo dataVo = this.dataService.queryAll(condition,size,num);
        if (dataVo!=null){
            return ResultVo.builder(200, "查询成功", dataVo);
        }
        return ResultVo.builder(500, "当前任务没有数据");
    }

    @GetMapping("export")
    public ResponseEntity<byte[]> export(@RequestParam("taskName")String taskName){
        return this.dataService.export(taskName);
    }

    @GetMapping("bar")
    public BarVo getBarVo(){
        return this.dataService.getBarData();
    }

}
